package com.loper7.base.utils;

import android.content.Intent;
import android.support.multidex.MultiDexApplication;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import com.kingja.loadsir.core.LoadSir;
import com.loper7.base.R;
import com.loper7.base.utils.loadsir.EmptyCallback;
import com.loper7.base.utils.loadsir.ErrorCallback;
import com.loper7.base.utils.loadsir.LoadingCallback;
import com.loper7.base.utils.loadsir.PlaceholderDetailsCallback;
import com.loper7.base.utils.loadsir.PlaceholderListCallback;
import com.loper7.base.utils.loadsir.TimeoutCallback;
import com.tencent.smtt.sdk.QbSdk;

import es.dmoral.toasty.Toasty;

/**
 * @author loper7
 * @version 1.0
 * @created 2017-10-11
 */
public class BaseApplication extends MultiDexApplication {

    private static BaseApplication baseApplication;


    public static BaseApplication getBaseApplication() {
        return baseApplication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        baseApplication = this;
        //屏幕适配
//        DensityUtil.setDensity(this);
        init();
    }

    /**
     * 初始化
     */
    protected void init() {
        LoadSir.beginBuilder()
                .addCallback(new ErrorCallback())
                .addCallback(new EmptyCallback())
                .addCallback(new LoadingCallback())
                .addCallback(new TimeoutCallback())
                .addCallback(new PlaceholderDetailsCallback())
                .addCallback(new PlaceholderListCallback())
                .setDefaultCallback(LoadingCallback.class)
                .commit();

        Toasty.Config.getInstance()
                .setErrorColor(ContextCompat.getColor(this, R.color.colorTransparent80))
                .setInfoColor(ContextCompat.getColor(this, R.color.colorTransparent80))
                .setSuccessColor(ContextCompat.getColor(this, R.color.colorTransparent80))
                .setWarningColor(ContextCompat.getColor(this, R.color.colorTransparent80))
                .setTextSize(14)
                .apply();

        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
            @Override
            public void onViewInitFinished(boolean arg0) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
            }
        };
        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);

    }




}
